/********************************************************************
	Copyright (C) 2006-2008 Lensow
	http://www.lensow.com
	Created:	2008/06/09   18:11
	Filename: 	x:\Lensow\Loplayer\src\libcore\PlayerSettings.h
	Author:		Dean

	Purpose:
*********************************************************************/
#pragma once
#include <strmif.h>
#include <atlcoll.h>

#pragma warning(disable : 4996)
enum 
{
	WM_GRAPHNOTIFY = WM_APP+1,
	WM_REARRANGERENDERLESS,
	WM_RESUMEFROMSTATE,
	WM_ISD3DFULLSCREENMODE,
	WM_VIDEOSIZE,
};
/////////////////////////////////////////////////////////////////////////////
// Casimir666
//
typedef enum ControlType{
	Brightness	= 0x1,
	Contrast	= 0x2,
	Hue			= 0x4,
	Saturation	= 0x8,
} 	ControlType;

typedef struct COLORPROPERTY_RANGE{ // _VMR9ProcAmpControlRange
	DWORD dwSize;
	DWORD dwProperty;
	float MinValue;
	float MaxValue;
	float DefaultValue;
	float StepSize;
} 	COLORPROPERTY_RANGE;

#define MAX_DVD_POSITION		5
typedef struct DVD_POSITION{
	ULONGLONG			llDVDGuid;
	ULONG				lTitle;
	DVD_HMSF_TIMECODE	Timecode;
} DVD_POSITION;

#define MAX_FILE_POSITION		5
typedef struct FILE_POSITION{
	CString				strFile;
	LONGLONG			llPosition;
} FILE_POSITION;

/////////////////////////////////////////////////////////////////////////////
// CMPlayerCApp:
// See mplayerc.cpp for the implementation of this class
//

// flags for AppSettings::nCS
enum {
	CS_NONE = 0,
	CS_SEEKBAR = 1,
	CS_TOOLBAR = CS_SEEKBAR << 1,
	CS_INFOBAR = CS_TOOLBAR << 1,
	CS_STATSBAR = CS_INFOBAR << 1,
	CS_STATUSBAR = CS_STATSBAR << 1,
	CS_LAST = CS_STATUSBAR
};

enum {
	CLSW_NONE = 0,
	CLSW_OPEN = 1,
	CLSW_PLAY = CLSW_OPEN << 1,
	CLSW_CLOSE = CLSW_PLAY << 1,
	CLSW_STANDBY = CLSW_CLOSE << 1,
	CLSW_HIBERNATE = CLSW_STANDBY << 1,
	CLSW_SHUTDOWN = CLSW_HIBERNATE << 1,
	CLSW_LOGOFF = CLSW_SHUTDOWN << 1,
	CLSW_AFTERPLAYBACK_MASK = CLSW_CLOSE | CLSW_STANDBY | CLSW_SHUTDOWN | CLSW_HIBERNATE | CLSW_LOGOFF,
	CLSW_FULLSCREEN = CLSW_LOGOFF << 1,
	CLSW_NEW = CLSW_FULLSCREEN << 1,
	CLSW_HELP = CLSW_NEW << 1,
	CLSW_DVD = CLSW_HELP << 1,
	CLSW_CD = CLSW_DVD << 1,
	CLSW_ADD = CLSW_CD << 1,
	CLSW_MINIMIZED = CLSW_ADD << 1,
	CLSW_REGEXTVID = CLSW_MINIMIZED << 1,		// 16
	CLSW_REGEXTAUD = CLSW_REGEXTVID << 1,
	CLSW_UNREGEXTVID = CLSW_REGEXTAUD << 1,
	CLSW_UNREGEXTAUD = CLSW_UNREGEXTVID << 1,
	CLSW_STARTVALID = CLSW_UNREGEXTAUD << 1,
	CLSW_NOFOCUS = CLSW_STARTVALID << 1,
	CLSW_FIXEDSIZE = CLSW_NOFOCUS << 1,
	CLSW_MONITOR = CLSW_FIXEDSIZE << 1,
	CLSW_INSTALLPN31 = CLSW_MONITOR << 1,
	CLSW_UNINSTALLPN31 = CLSW_INSTALLPN31 << 1,
	CLSW_D3DFULLSCREEN = CLSW_UNINSTALLPN31 << 1,
	CLSW_ADMINOPTION = CLSW_D3DFULLSCREEN << 1,
	CLSW_SLAVE = CLSW_ADMINOPTION << 1,
	CLSW_UNRECOGNIZEDSWITCH = CLSW_SLAVE << 1
};

enum {
	VIDRNDT_DS_DEFAULT,
	VIDRNDT_DS_OLDRENDERER,
	VIDRNDT_DS_OVERLAYMIXER,
	VIDRNDT_DS_VMR7WINDOWED,
	VIDRNDT_DS_VMR9WINDOWED,
	VIDRNDT_DS_VMR7RENDERLESS,
	VIDRNDT_DS_VMR9RENDERLESS,
	VIDRNDT_DS_DXR,
	VIDRNDT_DS_NULL_COMP,
	VIDRNDT_DS_NULL_UNCOMP,
	VIDRNDT_DS_EVR,
	VIDRNDT_DS_EVR_CUSTOM,
};

enum {
	VIDRNDT_RM_DEFAULT,
	VIDRNDT_RM_DX7,
	VIDRNDT_RM_DX9,
};

enum {
	VIDRNDT_QT_DEFAULT,
	VIDRNDT_QT_DX7,
	VIDRNDT_QT_DX9,
};

enum {
	VIDRNDT_AP_SURFACE,
	VIDRNDT_AP_TEXTURE2D,
	VIDRNDT_AP_TEXTURE3D,
};

#define AUDRNDT_NULL_COMP _T("Null Audio Renderer (Any)")
#define AUDRNDT_NULL_UNCOMP _T("Null Audio Renderer (Uncompressed)")

enum {
	SRC_CDDA = 1,
	SRC_CDXA = SRC_CDDA << 1,
	SRC_VTS = SRC_CDXA << 1,
	SRC_FLIC = SRC_VTS << 1,
	SRC_D2V = SRC_FLIC << 1,
	SRC_DTSAC3 = SRC_D2V << 1,
	SRC_MATROSKA = SRC_DTSAC3 << 1,
	SRC_SHOUTCAST = SRC_MATROSKA << 1,
	SRC_REALMEDIA = SRC_SHOUTCAST << 1,
	SRC_AVI = SRC_REALMEDIA << 1,
	SRC_RADGT = SRC_AVI << 1,
	SRC_ROQ = SRC_RADGT << 1,
	SRC_OGG = SRC_ROQ << 1,
	SRC_NUT = SRC_OGG << 1,
	SRC_MPEG = SRC_NUT << 1,
	SRC_DIRAC = SRC_MPEG << 1,
	SRC_MPA = SRC_DIRAC << 1,
	SRC_DSM = SRC_MPA << 1,
	SRC_SUBS = SRC_DSM << 1,
	SRC_MP4 = SRC_SUBS << 1,
	SRC_FLV = SRC_MP4 << 1,
	SRC_LAST = SRC_FLV << 1
};

enum {
	TRA_MPEG1 = 1,
	TRA_MPEG2 = TRA_MPEG1 << 1,
	TRA_RV = TRA_MPEG2 << 1,
	TRA_RA = TRA_RV << 1,
	TRA_MPA = TRA_RA << 1,
	TRA_LPCM = TRA_MPA << 1,
	TRA_AC3 = TRA_LPCM << 1,
	TRA_DTS = TRA_AC3 << 1,
	TRA_AAC = TRA_DTS << 1,
	TRA_PS2AUD = TRA_AAC << 1,
	TRA_DIRAC = TRA_PS2AUD << 1,
	TRA_VORBIS = TRA_DIRAC << 1,
	TRA_FLV4 = TRA_VORBIS << 1,
	TRA_VP62 = TRA_FLV4 << 1,
	TRA_H264 = TRA_VP62 << 1,
	TRA_WVC1 = TRA_H264 << 1,
	TRA_XVID = TRA_WVC1 << 1,
	TRA_DIVX = TRA_XVID << 1,
	TRA_WMV = TRA_DIVX << 1,
	TRA_MSMPEG4 = TRA_WMV << 1,
	TRA_SVQ3 = TRA_MSMPEG4 << 1,
	TRA_H263 = TRA_SVQ3 << 1,
	TRA_AMVV = TRA_H263 << 1,
	TRA_THEORA = TRA_AMVV << 1,
	TRA_LAST = TRA_THEORA << 1
};

enum {
	DVS_HALF,
	DVS_NORMAL,
	DVS_DOUBLE,
	DVS_STRETCH,
	DVS_FROMINSIDE,
	DVS_FROMOUTSIDE
};


class FilterOverride
{
public:
	bool fDisabled, fTemporary;
	enum {REGISTERED, EXTERNAL} type;
	// REGISTERED
	CComBSTR dispname;
	// EXTERNAL
	CString path, name;
	CLSID clsid;
	// props
	CAtlList<GUID> guids, backup;
	enum {PREFERRED, BLOCK, MERIT};
	int iLoadType;
	DWORD dwMerit;

	FilterOverride() {
		fDisabled = fTemporary = false;
		clsid = GUID_NULL;
		iLoadType = dwMerit = 0;
	}
	FilterOverride(FilterOverride* f) {
		fDisabled = f->fDisabled;
		fTemporary = f->fTemporary;
		type = f->type;
		dispname = f->dispname;
		path = f->path;
		name = f->name;
		clsid = f->clsid;
		guids.AddTailList(&f->guids);
		backup.AddTailList(&f->backup);
		iLoadType = f->iLoadType;
		dwMerit = f->dwMerit;
	}
};


/*
 *
 */
struct LOP_SETTINGS {
	//=============================================================================
	bool IsD3DFullscreen() const {
		if (nCLSwitches&CLSW_D3DFULLSCREEN)
			return true;
		else
			return fD3DFullscreen;

	}
	//=============================================================================
	const DVD_POSITION* CurrentDVDPosition() const {
		if (nCurrentDvdPosition != -1)
			return &DvdPosition[nCurrentDvdPosition];
		else
			return NULL;
	}
	//=============================================================================
	bool NewDvd(ULONGLONG llDVDGuid) {
		int			i;

		// Recherche si la position du DVD est connue
		for (i = 0; i < MAX_DVD_POSITION; i++) {
			if (DvdPosition[i].llDVDGuid == llDVDGuid) {
				nCurrentDvdPosition = i;
				return false;
			}
		}

		// Si DVD inconnu, le mettre en premier
		for (int i = MAX_DVD_POSITION - 1; i > 0; i--)
			memcpy (&DvdPosition[i], &DvdPosition[i-1], sizeof(DVD_POSITION));
		DvdPosition[0].llDVDGuid	= llDVDGuid;
		nCurrentDvdPosition			= 0;
		return true;
	}
	//=============================================================================
	const FILE_POSITION*	CurrentFilePosition() const {
		if (nCurrentFilePosition != -1)
			return &FilePosition[nCurrentFilePosition];
		else
			return NULL;
	}
	//=============================================================================
	bool NewFile(LPCTSTR strFileName) {
		int			i;

		// Recherche si la position du fichier est connue
		for (i = 0; i < MAX_FILE_POSITION; i++) {
			if (FilePosition[i].strFile == strFileName) {
				nCurrentFilePosition = i;
				return false;
			}
		}

		// Si fichier inconnu, le mettre en premier
		for (int i = MAX_FILE_POSITION - 1; i > 0; i--) {
			FilePosition[i].strFile		= FilePosition[i-1].strFile;
			FilePosition[i].llPosition	= FilePosition[i-1].llPosition;
		}
		FilePosition[0].strFile		= strFileName;
		FilePosition[0].llPosition	= 0;
		nCurrentFilePosition		= 0;
		return true;
	}

	//=============================================================================
	static void DeserializeHex (LPCTSTR strVal, BYTE* pBuffer, int nBufSize) {
		long		lRes = 0;

		for (int i = 0; i < nBufSize; i++) {
			_stscanf (strVal + (i*2), _T("%02x"), &lRes);
			pBuffer[i] = (BYTE)lRes;
		}
	}

	//=============================================================================
	static CString SerializeHex (const BYTE* pBuffer, const int nBufSize) {
		CString		strTemp;
		CString		strResult;

		for (int i = 0; i < nBufSize; i++) {
			strTemp.Format (_T("%02x"), pBuffer[i]);
			strResult += strTemp;
		}

		return strResult;
	}

public:
	bool fInitialized;
	// cmdline params
	int nCLSwitches;
	CStringList slFiles, slDubs, slSubs, slFilters;
	LONGLONG rtShift;
	LONGLONG rtStart;
	CSize fixedWindowSize;
	// int iFixedWidth, iFixedHeight;
	int iMonitor;


	bool fXpOrBetter;
	int iDXVer;
	int iAdminOption;

	int nCS;
	bool fHideCaptionMenu;
	int iDefaultVideoSize;
	bool fKeepAspectRatio;
	bool fCompMonDeskARDiff;


	CAutoPtrList<FilterOverride> filters;

	int iDSVideoRendererType;
	int iRMVideoRendererType;
	int iQTVideoRendererType;
	int iAPSurfaceUsage;
	bool fVMRSyncFix;
	int iDX9Resizer;
	bool fVMR9MixerMode;
	bool fVMR9MixerYUV;

	int nVolume;
	int nBalance;
	bool fMute;
	int nLoops;
	bool fLoopForever;
	bool fRewind;
	int iZoomLevel;
	// int iVideoRendererType;
	CString AudioRendererDisplayName;
	bool fAutoloadAudio;
	bool fAutoloadSubtitles;
	bool fEnableWorkerThreadForOpening;
	bool fReportFailedPins;

	bool fAllowMultipleInst;
	int iTitleBarTextStyle;
	bool fTitleBarTextTitle;
	int iOnTop;
	bool fTrayIcon;
	bool fRememberZoomLevel;
	bool fShowBarsWhenFullScreen;
	int nShowBarsWhenFullScreenTimeOut;
	bool fExitFullScreenAtTheEnd;
	bool fRememberWindowPos;
	bool fRememberWindowSize;
	bool fSnapToDesktopEdges;
	CRect rcLastWindowPos;
	UINT lastWindowType;
	CSize AspectRatio;
	bool fKeepHistory;

	CString sDVDPath;
	bool fUseDVDPath;
	LCID idMenuLang, idAudioLang, idSubtitlesLang;
	bool fAutoSpeakerConf;

	bool fOverridePlacement;
	int nHorPos, nVerPos;
	int nSPCSize;
	int nSPCMaxRes;
	int nSubDelayInterval;
	bool fSPCPow2Tex;
	bool fEnableSubtitles;

	bool fDisabeXPToolbars;
	bool fUseWMASFReader;
	int nJumpDistS;
	int nJumpDistM;
	int nJumpDistL;
	bool fFreeWindowResizing;
	bool fNotifyMSN;
	bool fNotifyGTSdll;

	bool fEnableAudioSwitcher;
	bool fDownSampleTo441;
	bool fAudioTimeShift;
	int tAudioTimeShift;
	bool fCustomChannelMapping;
	DWORD pSpeakerToChannelMap[18][18];
	bool fAudioNormalize;
	bool fAudioNormalizeRecover;
	float AudioBoost;

	bool fIntRealMedia;
	// bool fRealMediaRenderless;
	int iQuickTimeRenderer;
	float RealMediaQuickTimeFPS;

	CStringArray m_pnspresets;

	HACCEL hAccel;

	bool fWinLirc;
	CString WinLircAddr;
	bool fUIce;
	CString UIceAddr;
	bool fGlobalMedia;

	UINT SrcFilters, TraFilters;

	CString logofn;
	bool logoext;

	bool fHideCDROMsSubMenu;

	DWORD priority;
	bool launchfullscreen;

	BOOL fEnableWebServer;
	int nWebServerPort;
	bool fWebServerPrintDebugInfo;
	bool fWebServerUseCompression;
	bool fWebServerLocalhostOnly;
	CString WebRoot, WebDefIndex;
	CString WebServerCGI;

	CString SnapShotPath, SnapShotExt;
	int ThumbRows, ThumbCols, ThumbWidth;

	CString ISDb;

	//struct Shader {
	//	CString label, target, srcdata;
	//};
	//CAtlList<Shader> m_shaders;
	//CString m_shadercombine;

	bool			fTearingTest;
	bool			fDisplayStats;
	// === CASIMIR666 : nouveau settings
	bool			fD3DFullscreen;
	bool			fMonitorAutoRefreshRate;
	bool			fLastFullScreen;
	float			dBrightness;
	float			dContrast;
	float			dHue;
	float			dSaturation;
	CString			strShaderList;

	bool			fRememberDVDPos;
	bool			fRememberFilePos;
	bool			fShowOSD;
	int				iEvrBuffers;
	int				iLanguage;

	HWND			hMasterWnd;
protected:
	DVD_POSITION	DvdPosition[MAX_DVD_POSITION];
	int				nCurrentDvdPosition;
	FILE_POSITION	FilePosition[MAX_FILE_POSITION];
	int				nCurrentFilePosition;

};
